package com.zhss.ddd.lottery.draw.core.contorller;

import com.zhss.ddd.lottery.draw.activity.api.ILotteryDrawActivity;
import com.zhss.ddd.lottery.draw.core.entity.DrawLottery;
import com.zhss.ddd.lottery.draw.core.spring.SpringContext;
import com.zhss.ddd.lottery.draw.risk.control.api.RiskControlApi;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 抽奖controller组件
 */
@RestController
public class LotteryDrawController {

    @Autowired
    private SpringContext springContext;

    /**
     * 抽奖接口
     *
     * @param userId                用户id
     * @param lotteryDrawActivityId 抽奖活动id
     */
    @GetMapping("/draw-lottery")
    public String drawLottery(Long userId, Long lotteryDrawActivityId) {
        System.out.println("用户【" + userId + "】进行抽奖，抽奖活动为【" + lotteryDrawActivityId + "】");
        // 抽奖行为：参数转换成DDD实体
        DrawLottery drawLottery = springContext.getBean(DrawLottery.class);
        drawLottery.setUserId(userId);
        drawLottery.setLotteryDrawActivityId(lotteryDrawActivityId);
        // 执行抽奖的行为
        return drawLottery.execute();
    }

}
